package com.ga01.controller;

import com.ga01.entity.Goal;
import com.ga01.service.GoalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goals")
public class GoalController {

    @Autowired
    private GoalService goalService;

    @GetMapping
    public List<Goal> getAllGoals() {
        return goalService.list();
    }

    @GetMapping("/{id}")
    public Goal getGoalById(@PathVariable Integer id) {
        return goalService.getById(id);
    }

    @PostMapping
    public boolean addGoal(@RequestBody Goal goal) {
        return goalService.save(goal);
    }

    @PutMapping
    public boolean updateGoal(@RequestBody Goal goal) {
        return goalService.updateById(goal);
    }

    @DeleteMapping("/{id}")
    public boolean deleteGoal(@PathVariable Integer id) {
        return goalService.removeById(id);
    }
}